package com.woniuxy.micropromotionserver.promotionmag.mapper;

import com.woniuxy.micropromotionserver.bean.PageRequest;
import com.woniuxy.micropromotionserver.bean.PromotionBean;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface PromotionOrderMapper {

    /**
     * 1增加一条促销订单
     * @param promotionBean
     * @return
     */
    @Insert("insert into t_promotion_info(promotion_code,fk_store_id,start_time,end_time," +
            "activity_time,promotion_cycle,fk_rule_id,promo_type,handling_personnel,remarks," +
            "voucher_maker,preparation_time,audit_status,auditor,audit_time,audit_remarks,del_status,promotion_status)" +
            "values (#{po.promotionCode},#{po.fkStoreId},#{po.startTime},#{po.endTime}," +
            "#{po.activityTime},#{po.promotionCycle},#{po.Rule},#{po.promoType},#{po.handlingPersonnel}," +
            "#{po.remarks},#{po.voucherMaker},now(),'0',#{po.auditor},#{po.auditTime},'未审核','0','1'" +
            ")")
    int savePromotionBean(@Param("po") PromotionBean promotionBean);



    /**
     * 2 将传入id的促销单进行修改  审核 把审核状态改为 1（审核成功）或 2（审核失败）
     *  或者是把 删除 把删除状态改为 1
     * 还有审核备注也可以改
     * @param promotionBean
     * @return 受影响的行数
     */
    @Update("<script>" +
            "update t_promotion_info" +
            "<set>" +
            "<if test='po.auditStatus != null'>" +
            " audit_status = #{po.auditStatus}," +
            "</if>" +
            "<if test='po.auditRemarks != null '>" +
            " audit_remarks = #{po.auditRemarks}," +
            "</if>" +
            "<if test='po.delStatus != null'>" +
            " del_status = '1' ," +
            "</if>" +
            "</set>" +
            "where id = #{po.id}" +
            "</script>")
    int updatePromotionBean(@Param("po")PromotionBean promotionBean);


    /**
     *  3 根据促销id 查询某一条促销单的信息
     * @param id
     * @return
     */
        PromotionBean findByPromotionId(Long id);


    /**
     *  4 查询消息 根据促销单类型promo_type  分页
     *   查询的促销单 1 订单促销  2商品促销
     *   删除状态为  未删除0  1已删除
     * @param request
     * @param promotionBean
     * @return
     */
    List<PromotionBean> findByPromoType(@Param("p") PageRequest request, @Param("o")PromotionBean promotionBean);









}
